package cn.clx.ymcc.rocketmq;

import cn.clx.ymcc.domain.MediaFile;
import cn.clx.ymcc.service.IMediaFileService;
import com.alibaba.fastjson.JSONObject;
import io.netty.util.CharsetUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

@Slf4j
@Component
@RocketMQMessageListener(topic = "media-topic",
        selectorExpression="media-tags"	//tags
                ,consumerGroup = "service-consumer"
        ,messageModel = MessageModel.CLUSTERING )
public class MessageConsumer implements RocketMQListener<MessageExt> {

    @Autowired
    private IMediaFileService mediaFileServiceimpl;


    @Override
    @Transactional
    public void onMessage(MessageExt message) {
        String msg = new String(message.getBody(), CharsetUtil.UTF_8);
        MediaFile mediaFile = JSONObject.parseObject(msg, MediaFile.class);
        mediaFileServiceimpl.handleFile2m3u8(mediaFile);

    }
}